home *** CD-ROM | disk | FTP | other *** search
/ PD ROM 1 / PD ROM Volume I - Macintosh Software from BMUG (1988).iso / Stacks / Updates⁄New / TEXAS for BMUG / C progs / TEXAS XFCNs ƒ / delFiles.z1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-12-29  |  2.9 KB  |  148 lines  |  [TEXT/KAHL]

  1. /* a HyperCard XFCN that lets you delete some files from the disk
  2.  * ... by giving the user the std files dialog
  3.  * repeatedly ....
  4.  *
  5.  * call it as HyperTalk function:    delFiles (x0, y0)
  6.  *
  7.  * where x0, y0 are the screen coordinates to base the dialog boxes
  8.  * on ... 0,0 works for a Mac Plus....
  9.  *
  10.  * Don't bother with any error checking ... just do it!
  11.  *
  12.  * make it XFCN number 2232 and name it "delFiles"
  13.  *
  14.  * 871229 ^z
  15.  */
  16.  
  17.  
  18. #include <MacTypes.h>
  19. #include <OSUtil.h>
  20. #include <FileMgr.h>
  21. #include <StdFilePkg.h>
  22. #include <WindowMgr.h>
  23. #include <HyperXCmd.h>
  24.  
  25. pascal void main (XCmdBlockPtr paramPtr);
  26. int GetFileZ (Str255 *fn, int *vRef, int x0, int y0);
  27. void pStrCopy (char *p1, char *p2);
  28. long atol (char *s);
  29.  
  30. pascal void main (paramPtr)
  31.   XCmdBlockPtr paramPtr;
  32.   {
  33.     WindowRecord w_record;
  34.     WindowPtr info_window;
  35.     Rect b_rect;
  36.     Str255 fn0;
  37.     int vRef0, x0, y0;
  38.  
  39.     if (paramPtr->paramCount != 2)
  40.       {
  41.           SysBeep (10);
  42.           return;
  43.       }
  44.     x0 = atol (*(paramPtr->params[0]));
  45.     y0 = atol (*(paramPtr->params[1]));
  46.  
  47.     b_rect.top = 30 + y0;
  48.     b_rect.left = 12 + x0;
  49.     b_rect.bottom = 52 + y0;
  50.     b_rect.right = 500 + x0;
  51.     info_window = NewWindow (&w_record, &b_rect, "\p", (Boolean)1, dBoxProc,
  52.         (WindowPtr)-1, (Boolean)0, (long)0);
  53.     ShowWindow (info_window);
  54.     SetPort (info_window);
  55.     TextFont (0);
  56.     b_rect.top = 0;
  57.     b_rect.left = 0;
  58.     b_rect.bottom = 22;
  59.     b_rect.right = 488;
  60.  
  61.     EraseRect (&b_rect);
  62.     MoveTo ( 4,15);
  63.     DrawString ("\pSelect file(s) to (irreversibly!) delete ... choose 'Cancel' when done.");
  64.  
  65.     while (GetFileZ (&fn0, &vRef0, x0, y0))
  66.         FSDelete (fn0, vRef0);
  67.  
  68.     CloseWindow (info_window);
  69.     return;
  70.   }
  71.  
  72.  
  73. /* following variables and routine do the standard files dialog
  74.  * to get the name of the file to use ... cribbed from the MiniEdit
  75.  * example that comes with LSC....  put the dialog box someplace
  76.  * reasonable, nothing complex ....
  77.  */
  78.  
  79. int GetFileZ (fnp, vRefp, x0, y0)
  80.   Str255 *fnp;
  81.   int *vRefp, x0, y0;
  82.   {
  83.     SFTypeList myTypes;
  84.     Point SFGwhere;
  85.     SFReply reply;
  86.  
  87.     SFGwhere.v = 90 + y0;
  88.     SFGwhere.h = 82 + x0;
  89.     
  90.     SFGetFile( SFGwhere, "\p", 0L, -1, myTypes, 0L, &reply);
  91.     
  92.     if (reply.good)
  93.       {
  94.         pStrCopy( (char *)reply.fName, (char *)fnp);
  95.         *vRefp = reply.vRefNum;
  96.         return (1);
  97.       }
  98.     else return (0);
  99.   }
  100.  
  101.  
  102. /* routine to copy a pascal string from one place to another.... used in
  103.  * above Standard Files routine.... from LSC library....
  104.  */
  105.  
  106. void pStrCopy (p1, p2 )
  107.   register char *p1, *p2;
  108.   {
  109.     register int len;
  110.     
  111.     len = *p2++ = *p1++;
  112.     while (--len >= 0)
  113.         *p2++ = *p1++;
  114.     return;
  115.   }
  116.  
  117.  
  118. /* function to convert alphabetic string to a long integer ... from LSC
  119.  * library.... simplified to avoid using isspace() & isdigit() ....
  120.  */
  121.  
  122. long atol (s)
  123.   register char *s;
  124.   {
  125.     register char signflag = 0;
  126.     register long r = 0;
  127.  
  128.     while ((*s == ' '))
  129.         s++;
  130.         
  131.     if (*s == '-')
  132.       {
  133.         signflag = 1;
  134.         s++;
  135.       }
  136.     else if (*s == '+')
  137.          s++;
  138.  
  139.     while (*s >= '0' && *s <= '9') 
  140.         r = r * 10 + (*s++ - '0');
  141.     
  142.     return (signflag ? -r : r);
  143. }
  144.  
  145.  
  146.  
  147.  
  148.